<template>
  <Dialogdrawerdefect :ddtvisible="dialogVisible" size="452px" :has-modal="false" :modal="false" @close="handleClose" title="黑名单规则配置">
    <div class="col-right" v-loading="loading">
      <el-form inline class="rule-form" ref="form" :model="ruleForm" :rules="rules">
        <div class="sub-title">黑名单配置医院</div>
        <el-form-item label="医院代码：" prop="hospitalCode" class="short-input">
          <el-select
            size="small"
            class="param-type_input"
            filterable
            v-model="ruleForm.hospitalCode"
            placeholder="请选择"
            @change="hospitalChange">
            <el-option
              v-for="(item,index) in mx_hospitalList"
              :key="index"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <div class="sub-title">黑名单触发规则</div>
        <el-form-item label="爽约：" prop="foperatorno" class="short-input">
          <el-input size="small" v-model="ruleForm.foperatorno"></el-input>
          <span class="word">次</span>
        </el-form-item>
        <div class="sub-title">解禁规则</div>
        <el-form-item label="自动解禁：" prop="scheduledDep" class="short-input">
          <el-select size="small" v-model="ruleForm.scheduledDep" placeholder="请选择天数" clearable>
            <el-option
              v-for="(item,index) in timesOptions"
              :key="index"
              :label="item.item"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <div class="sub-title">申请限制</div>
        <el-form-item label="黑名单申请限制：" prop="type">
          <el-checkbox-group v-model="ruleForm.type">
            <el-checkbox label="a" name="type">转诊预约</el-checkbox>
            <el-checkbox label="b" name="type">外院预约</el-checkbox>
            <el-checkbox label="c" name="type">临床预约</el-checkbox>
            <el-checkbox label="d" name="type">自助预约</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div class="buttons">
        <div class="right-buttons">
          <el-button size="small" @click="handleClose">关 闭</el-button>
          <el-button size="small" type="primary" @click="handleConfirm">确 定</el-button>
        </div>
      </div>
    </div>
  </Dialogdrawerdefect>
</template>
<script>
import Dialogdrawerdefect from '@/components/dialogbox/dialogDrawerDefect'
import { getItemList } from '@/api/api.js'

export default {
  name: 'EditDialog',
  components: {
    Dialogdrawerdefect
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    hospitalCode: {
      String,
      default: ''
    }
  },
  data() {
    return {
      ruleForm: {
        hospitalCode: '',
        type: []
      },
      loading: false,
      rules: {
        hospitalCode: [{ required: true, message: '请选择医院', trigger: 'blur' }]
      },
      timesOptions: []
    }
  },
  watch: {
    async dialogVisible(val) {
      if (val) {
        this.ruleForm.hospitalCode = this.hospitalCode
        await this.$getHospitalList()
        this.getDetail()
        this.getTimesOptions()
      } else {
        this.ruleForm = {
          hospitalCode: '',
          type: []
        }
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('update:dialogVisible', false)
    },
    getDetail() {
    //   this.loading = true
    //   getFlogModel({ hospitalCode: this.ruleForm.hospitalCode }).then(res => {
    //     this.loading = false
    //     if (res && res.code === 10000) {
    //       this.ruleForm = res.content
    //       let obj = this.mx_hospitalList.find(v => {
    //         return v.code === this.ruleForm.hospitalCode
    //       })
    //       if (obj) {
    //         this.ruleForm.hospitalName = obj.name
    //       }
    //       this.dealAllContent()
    //     }
    //   }).catch(() => {
    //     this.loading = false
    //   })
    },
    handleConfirm() {
      // 保存
    },
    hospitalChange() {
      this.getDetail()
    },
    getTimesOptions() {
      // 获取预约来源
      let data = {
        HospitalCode: this.ruleForm.hospitalCode,
        type: '解禁时间'
      }
      getItemList(data).then(res => {
        if (res && res.code === 10000) {
          this.timesOptions = res.content.list.sort((a, b) => {
            return a.itemValue - b.itemValue
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.col-right{
        border-left: 1px solid #e5e5e5;
        padding: 0px 20px 47px;
        color: #606266;
        background-color: #FFFFFF;
        .sub-title{
            font-weight: 600;
        }
        .short-input{
            width: 260px;
            margin-right: 23px!important;
            margin-bottom: 5px;
            .el-input{
                width: 200px;
            }
            .word{
                margin-left: 5px;
            }
        }
        .el-form-item{
            /deep/ .el-form-item__label{
                font-weight: 500;
            }
        }
        .mini-input{
            width: 185px;
            margin-right: 15px !important;
            margin-bottom: 5px;
            .el-input{
                width: 185px;
            }
        }
        .large-width{
            width: 424px;
            /deep/ .el-textarea__inner{
                width: 424px;
            }
        }
        .describe-input{
            width: 350px;
            .el-input{
                width: 350px;
            }
        }
        .name{
            font-weight: bold;
        }
        .el-form--inline .el-form-item{
            margin-right:0px
        }
        .buttons{
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            background: #fff;
            padding: 5px 25px;
            border-top: 1px solid #E5E7EC;
            line-height: 31px;
            /deep/ .el-form-item__content{
                width:100%
            }
            .right-buttons{
                float:right
            }
            .el-dropdown{
                color: #00c0ef;
            }
        }
        .text-block{
            background: #f5f5f5;
            padding: 0 10px;
            margin-top: 10px;
        }
        .content-block{
           padding: 0 10px;
        }
    }
</style>
